home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / updateAE.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  15.8 KB  |  548 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //    Created:     Sept 29, 1997
  22. //    Author:                ajp
  23. //
  24. //
  25. //<doc>
  26. //<name updateAE>
  27. //<owner "Alias|Wavefront Unsupported">
  28. //
  29. //<synopsis>
  30. //        updateAE ( string $node )
  31. //
  32. //<returns>
  33. //        None.
  34. //
  35. //<description>
  36. //        Displays the information for the named node in the attribute editor.
  37. //
  38. //<flags>
  39. //        string $node : Node name to show in the attribute editor.
  40. //
  41. //<examples>
  42. //    // Create some geometry
  43. //    sphere;
  44. //    cone;
  45. //
  46. //    // Show the attribute editor with the cone
  47. //    AttributeEditor; 
  48. //
  49. //    // Show the sphere in the attribute editor 
  50. //    updateAE "nurbsSphere1"
  51. //
  52. //</doc>
  53.  
  54. global string    $gAEFocusNode = "";
  55. global int         $gAENotesScriptJob = -1;
  56. global int         $gAENotesScriptJob2 = -1;
  57. global int         $gAENotesScriptJob3 = -1;
  58.  
  59. proc updateAEStack( string $node )
  60. // Update the stack used to keep track of the focus nodes brought
  61. // up in the attribtue editor.  This stack will be used as a navigation
  62. // tool under the Focus menu item in the attribute editor
  63. //
  64. {
  65.     global string    $gAENodeStack[];
  66.     global string    $gAEFocusNode;
  67.  
  68.     int        $maxStackSize = 10;
  69.     int        $nodeStackSize;
  70.     string    $tmp[] = `ls -l $node`;
  71.     string    $newNode = $tmp[0];
  72.     clear $tmp;
  73.  
  74.     // make a copy of the node stack
  75.     //
  76.     for ($i = (size($gAENodeStack)-1); $i >= 0; $i--) {
  77.         if ($gAENodeStack[$i] != "") {
  78.             $tmp[size($tmp)] = $gAENodeStack[$i];
  79.         }
  80.     }
  81.     $nodeStackSize = size($tmp);
  82.  
  83.     // clear the node stack
  84.     //
  85.     clear $gAENodeStack;
  86.     
  87.     // check if something has been renamed or deleted, possibly making
  88.     // some items in the list no longer valid
  89.     //
  90.     for ($i = 0; $i < $nodeStackSize; $i++) {
  91.         if (!`objExists $tmp[$i]`) {
  92.             $nodeStackSize--;
  93.             for ($j = $i; $j < $nodeStackSize; $j++) {
  94.                 $tmp[$j] = $tmp[$j+1];
  95.             }
  96.             $tmp[$nodeStackSize] = "";
  97.             $i--;
  98.         }
  99.     }
  100.  
  101.     // look through the list for an occurrence of this node
  102.     // if found, shuffle it to the end
  103.     //
  104.     int $found = false;
  105.     for ($i = 0; $i < $nodeStackSize; $i++) {
  106.         if ($newNode == $tmp[$i]) {
  107.             $found = true;
  108.             break;
  109.         }
  110.     }
  111.  
  112.     if ($found) {
  113.  
  114.         // shuffle this one to the bottom
  115.         for ($j = $i; $j < $nodeStackSize; $j++) {
  116.             $tmp[$j] = $tmp[$j+1];
  117.         }
  118.  
  119.         // add the node to the stack
  120.         $tmp[$nodeStackSize-1] = $newNode;
  121.  
  122.     } else if ($nodeStackSize >= $maxStackSize) {
  123.  
  124.         // shuffle everything up one to preserve max stack size
  125.         for ($i = 1; $i < $nodeStackSize; $i++) {
  126.             $tmp[$i-1] = $tmp[$i];
  127.         }
  128.  
  129.         // add the node to the stack
  130.         $tmp[$nodeStackSize-1] = $newNode;
  131.  
  132.     } else {
  133.  
  134.         // add the node to the stack
  135.         $tmp[$nodeStackSize] = $newNode;
  136.  
  137.     }
  138.  
  139.     // copy the $tmp array back into the global stack
  140.     //
  141.     for ($i = (size($tmp)-1); $i >= 0; $i--) {
  142.         if ($tmp[$i] != "") {
  143.             $gAENodeStack[size($gAENodeStack)] = $tmp[$i];
  144.         }
  145.     }
  146. }
  147.  
  148. global proc killScriptJobAENotes() 
  149. {
  150.     global int $gAENotesScriptJob;
  151.     global int $gAENotesScriptJob2;
  152.     global int $gAENotesScriptJob3;
  153.  
  154.     // Kill the current script job, if any
  155.     //
  156.     if( $gAENotesScriptJob != -1) { 
  157.         if( `scriptJob -exists $gAENotesScriptJob` ) {
  158.             catch(`scriptJob -force -kill $gAENotesScriptJob`);
  159.         }
  160.         $gAENotesScriptJob = -1;
  161.     }
  162.     if( $gAENotesScriptJob2 != -1) { 
  163.         if( `scriptJob -exists $gAENotesScriptJob2` ) {
  164.             catch(`scriptJob -force -kill $gAENotesScriptJob2`);
  165.         }
  166.         $gAENotesScriptJob2 = -1;
  167.     }
  168.     if( $gAENotesScriptJob3 != -1) { 
  169.         if( `scriptJob -exists $gAENotesScriptJob3` ) {
  170.             catch(`scriptJob -force -kill $gAENotesScriptJob3`);
  171.         }
  172.         $gAENotesScriptJob3 = -1;
  173.     }
  174. }
  175.  
  176. global proc setupScriptJobAENotes( string $fullNodeName, string $longAttrName ) 
  177. //
  178. //    Description:
  179. //        Sets up a script job that updates the Notes section 
  180. //        when this attribute changes.
  181. //
  182. {
  183.     global int $gAENotesScriptJob;
  184.     global int $gAENotesScriptJob2;
  185.     global int $gAENotesScriptJob3;
  186.     killScriptJobAENotes();
  187.  
  188.     // Don't do anything unless AE is actually showing
  189.  
  190.     string $nodeForNotes = $fullNodeName;
  191.  
  192.     // Get the full node name, but without components
  193.     // eg. |pCube1|pcubeShape1.vtx[3]  should be
  194.     //     |pCube1|pcubeShape1
  195.     //
  196.     string $buffer[];
  197.     if( tokenize( $nodeForNotes, ".", $buffer ) > 1 ) {
  198.         $nodeForNotes = $buffer[0];
  199.     }
  200.     
  201.     if( (size($nodeForNotes) == 0) || (!`objExists $nodeForNotes`) ) {
  202.         return;
  203.     }
  204.  
  205.     string $scriptJobCmd = "updateAENotes(\"" + $nodeForNotes + "\", \"" 
  206.         + $longAttrName + "\");";
  207.  
  208.     if( `attributeQuery -exists -n $nodeForNotes $longAttrName` ) {
  209.  
  210.         // Add a scriptJob so that when this attribute changes
  211.         // updateAENotes() is called
  212.         //
  213.         int $scriptJobNumber = `scriptJob -kws -protected
  214.             -attributeChange ($nodeForNotes+"."+$longAttrName) $scriptJobCmd`;
  215.             
  216.         // Store the script job number so we can kill it later
  217.         $gAENotesScriptJob = $scriptJobNumber;
  218.  
  219.         // Add a scriptJob so that when this attribute is deleted
  220.         // the Notes scroll field is blanked out
  221.         //
  222.         string $scriptJobCmd2 = "scrollField -e -text \"\" AENotesScrollField; ";
  223.         $scriptJobNumber = `scriptJob -kws -runOnce on -protected 
  224.             -attributeDeleted ($nodeForNotes+"."+$longAttrName) $scriptJobCmd2`;
  225.         $gAENotesScriptJob2 = $scriptJobNumber;
  226.  
  227.         // Add a scriptJob so that when this attribute is undone and redone
  228.         // the Notes scroll field is updated again
  229.         //
  230.         $scriptJobNumber = `scriptJob -kws -runOnce on -protected 
  231.             -attributeAdded ($nodeForNotes+"."+$longAttrName) $scriptJobCmd`;
  232.         $gAENotesScriptJob3 = $scriptJobNumber;
  233.  
  234.     } else {
  235.  
  236.         $scriptJobCmd += "$gAENotesScriptJob3 = -1;"
  237.             + "setupScriptJobAENotes(\"" 
  238.             + $nodeForNotes + "\"," 
  239.             + "\"" + $longAttrName  + "\""
  240.             + " );"
  241.             ;
  242.  
  243.         // The notes attribute doesn't exist yet.
  244.         // Add a scriptJob so that when this attribute is created
  245.         // the Notes scroll field is updated 
  246.         //
  247.         $scriptJobNumber = `scriptJob -kws -runOnce on -protected 
  248.             -attributeAdded ($nodeForNotes+"."+$longAttrName) $scriptJobCmd`;
  249.         $gAENotesScriptJob3 = $scriptJobNumber;
  250.  
  251.     }
  252. }
  253.  
  254. global proc updateAENotes( string $fullNodeName, string $longAttrName ) 
  255. //
  256. //    Description:
  257. //        Updates the Notes area to have the notes for the given node
  258. //        If there is no node then disable the text field.
  259. //        If there are no notes for the given text field, clear out the field.
  260. //
  261. {
  262.     string $nodeForNotes = $fullNodeName;
  263.     if( $nodeForNotes == "" )  {
  264.         // There is nothing to display.  Disable the entire Notes area
  265.         text -e -enable false AENotesTextLabel;
  266.         text -e -enable false AENotesTextLabel2;
  267.         text -e -label "   Notes:" AENotesTextLabel;
  268.         text -e -label "" AENotesTextLabel2;
  269.         scrollField -e -enable false AENotesScrollField;
  270.         scrollField -e -cc "" AENotesScrollField;
  271.         scrollField -e -ec "" AENotesScrollField;
  272.         scrollField -e -kpc "" AENotesScrollField;
  273.         scrollField -e -text "" AENotesScrollField;
  274.         return;
  275.     }
  276.  
  277.     text -e -enable true AENotesTextLabel;
  278.     scrollField -e -enable true AENotesScrollField;
  279.  
  280.     // Put the name of the node in the "Notes" line
  281.     // The name sometimes has the full path, eg. |pCone|pConeShape
  282.     // so parse out the last node name.
  283.     //
  284.     string $justNode = "";
  285.     string $buffer[];
  286.     int $numTokens = tokenize($nodeForNotes, "|", $buffer);
  287.     if( $numTokens > 0 ) {
  288.         $justNode = $buffer[$numTokens-1];
  289.  
  290.         // Remove any components, eg. pCube1.vtx[3]
  291.         //
  292.         if( tokenize( $justNode, ".", $buffer ) > 1 ) {
  293.             $justNode = $buffer[0];
  294.         }
  295.     }
  296.     text -e -label ("   Notes: " + $justNode ) AENotesTextLabel;
  297.     scrollField -e -ed true AENotesScrollField;
  298.  
  299.     // Get the full node name, but without components
  300.     // eg. |pCube1|pcubeShape1.vtx[3]  should be
  301.     //     |pCube1|pcubeShape1
  302.     //
  303.     if( tokenize( $nodeForNotes, ".", $buffer ) > 1 ) {
  304.         $nodeForNotes = $buffer[0];
  305.     }
  306.  
  307.     // Update the scroll field
  308.     // If the attribute exists, then put the attribute
  309.     // value into the scroll field.  Otherwise, clear out the scroll field
  310.     //
  311.     string $notes = "";
  312.     if( `attributeQuery -exists -n $nodeForNotes $longAttrName` ) {
  313.         $notes = `getAttr ($nodeForNotes + "." + $longAttrName)`;
  314.  
  315.         // If the notes attribute is locked, then
  316.         // don't allow editing of the attribute
  317.         // Also display helpful message "Notes are locked".
  318.         //
  319.         if( `getAttr -l ($nodeForNotes + "." + $longAttrName)` ) {
  320.             scrollField -e -ed false AENotesScrollField;
  321.         }
  322.     }
  323.     scrollField -e -text $notes AENotesScrollField;
  324.     text -e -enable false AENotesTextLabel2; 
  325.     text -e -label "" AENotesTextLabel2; 
  326.  
  327.     // Attach commands to the scroll field so 
  328.     // the node's note will update
  329.     //
  330.     {
  331.         string $shortAttrName= "nts";
  332.         string $attrTypeNotes = "string";
  333.         string $cc = getUpdateAENotesChangeCmd( $nodeForNotes,
  334.                 $longAttrName, $shortAttrName, $attrTypeNotes );
  335.         scrollField -e -cc $cc AENotesScrollField;
  336.         scrollField -e -ec $cc AENotesScrollField;
  337.  
  338.         $cc = getUpdateAENotesStatusCmd( $nodeForNotes, $longAttrName );
  339.         scrollField -e -kpc $cc AENotesScrollField;
  340.     }
  341. }
  342.  
  343. global proc updateAENotesStatus( string $nodeName,
  344.     string $longAttrName )
  345. //
  346. //    Description:
  347. //        This proc updates the "*" in the Notes title bar.  The "*" indicates
  348. //        whether or not the notes in the notes scroll field are different
  349. //        from the notes stored on the given node.
  350. //        Typically, this proc is attached to a cmd on the
  351. //        Notes scroll field.
  352. //
  353. {
  354.     int $enable = false;
  355.     string $label = "";
  356.     // if scrollField is enabled
  357.     // if notes attr exists
  358.     // if scrollField text is different from notes attr
  359.     //
  360.     if( `scrollField -q -enable AENotesScrollField` ) {
  361.         string $currentNotes = `scrollField -q -text AENotesScrollField`;
  362.  
  363.         if( `attributeQuery -exists -n $nodeName $longAttrName` ) {
  364.             string $attrNotes = `getAttr ($nodeName + "." + $longAttrName)`;
  365.             if( $currentNotes != $attrNotes ) {
  366.                 $enable = true;
  367.                 $label = "*";
  368.             }
  369.         } else if( size($currentNotes) > 0 ) {
  370.             $enable = true;
  371.             $label = "*";
  372.         }
  373.     }
  374.  
  375.     text -e -enable $enable AENotesTextLabel2;
  376.     text -e -label $label AENotesTextLabel2;
  377. }
  378.  
  379. global proc string getUpdateAENotesStatusCmd( string $nodeForNotes, 
  380.     string $longAttrName) 
  381. //
  382. //    Description:
  383. //        This returns a command string that can be attached as a callback 
  384. //        to update the "*" in the Notes title bar.  The "*" indicates
  385. //        whether or not the notes in the notes scroll field are different
  386. //        from the notes stored on the given node.
  387. //        Typically the string is attached to the "keyPressCommand"
  388. //        of the Notes scroll field.
  389. //
  390. //        The purpose of the evalDeferred is that the keyPressCommand
  391. //        of the Notes scroll field is executed before the key is
  392. //        actually processed.  ie. if the key is Backspace, the
  393. //        keyPressCommand is executed BEFORE any text is deleted
  394. //        in the scroll field.  Using evalDeferred means that the
  395. //        the updateAENotesStatus call will happen on the next idle event.
  396. //
  397. {
  398.     string $updateStatusCmd = "evalDeferred(\""
  399.         + "updateAENotesStatus( \\\"" 
  400.         + $nodeForNotes + "\\\","
  401.         + "\\\"" + $longAttrName  + "\\\""
  402.         + ");"
  403.         + "\");"
  404.         ;
  405.     return $updateStatusCmd;
  406. }
  407.  
  408. global proc string getUpdateAENotesChangeCmd( string $nodeForNotes, 
  409.     string $longAttrName, string $shortAttrName, string $attrType ) 
  410. //
  411. //    Description:
  412. //        This returns a command string that can be attached as a callback for
  413. //        a control, to update the Notes area.  When attached to the
  414. //        Notes scroll field control's change cmd, this will update
  415. //        the associated node's attribute.
  416. //         Also update script job so that it detects when this attribute
  417. //        has changed, (eg. with setAttr cmd) and will update the Notes
  418. //        control.
  419. //
  420. {
  421.     string $editCmd = "killScriptJobAENotes();"
  422.         + "setNotesAttribute( \"" 
  423.         + $nodeForNotes + "\","
  424.         + "\"" + $longAttrName  + "\","
  425.         + "\"" + $shortAttrName  + "\","
  426.         + "\"" + $attrType  + "\","
  427.         + "`scrollField -q -text AENotesScrollField`);"
  428.         + "text -e -enable false AENotesTextLabel2;"
  429.         + "text -e -label \"\" AENotesTextLabel2;"
  430.         + "setupScriptJobAENotes(\"" 
  431.         + $nodeForNotes + "\"," 
  432.         + "\"" + $longAttrName  + "\""
  433.         + " );"
  434.         ;
  435.     return $editCmd;
  436. }
  437.  
  438. global proc commitAENotes( string $nodeToCommit ) 
  439. // This proc is typically called before the AE is switched
  440. // from displaying one node to another.  At this point,
  441. // the notes from the first node need to be commited
  442. // before AE switches to the next node.
  443. //
  444. {
  445.     string $longAttrNameNotes = "notes";
  446.     string $shortAttrNameNotes = "nts";
  447.     string $attrTypeNotes = "string";
  448.  
  449.     // If notes area is editable, then proceed
  450.     //
  451.     if( `scrollField -q -ed AENotesScrollField` ) {
  452.  
  453.         // Figure out which node we're switching from
  454.         //
  455.         if( size($nodeToCommit) > 0 ) {
  456.  
  457.                string $notesToCommit = `scrollField -q -text AENotesScrollField`;
  458.     
  459.             // Apply the notes from the Notes area to the
  460.             // node that we're switching from
  461.             //
  462.              if( catch(setNotesAttribute( $nodeToCommit, 
  463.                 $longAttrNameNotes, $shortAttrNameNotes, $attrTypeNotes,
  464.                  $notesToCommit ) ) ) {
  465.                 // there was an error with setNotesAttribute
  466.                 // Ignore it since it's handled by setNotesAttribute
  467.             }
  468.             else {
  469.                 // Commit was complete.  
  470.                 text -e -enable false AENotesTextLabel2;
  471.                 text -e -label "" AENotesTextLabel2;
  472.             }
  473.         }
  474.     }
  475. }
  476.  
  477. global proc updateAE( string $node )
  478. // This proc calls other to build the tabs and controls for the
  479. // specified focus node.  
  480. //
  481. {
  482.     global string    $gAttributeEditorWindowName;
  483.     global string    $gAEMenuBarLayoutName;
  484.     global string    $gAENothingSelectedLayout;
  485.     global string    $gAEBaseLayoutName;
  486.     global string    $gAECurrentTab;
  487.     global string    $gAERelatedNodes[];
  488.     global string    $gAEFocusNode;
  489.  
  490.     global string    $gAETabLayoutName;
  491.     string $longAttrNameNotes = "notes";
  492.     string $shortAttrNameNotes = "nts";
  493.     string $attrTypeNotes = "string";
  494.  
  495.     setParent $gAEMenuBarLayoutName;
  496.  
  497.     if ($node == "" || !`objExists $node`) {
  498.  
  499.         formLayout -e -visible true $gAENothingSelectedLayout;
  500.         formLayout -e -visible false $gAEBaseLayoutName;
  501.         $gAEFocusNode = "";
  502.         if( `window -exists $gAttributeEditorWindowName` ) {
  503.             window -e
  504.                 -title ("Attribute Editor")
  505.                 $gAttributeEditorWindowName;
  506.         }
  507.         
  508.         // Disable the "Notes" section and clear out any text
  509.         updateAENotes( $node, $longAttrNameNotes );
  510.  
  511.         //  Kill any script jobs 
  512.         setupScriptJobAENotes( $node, $longAttrNameNotes );
  513.  
  514.         button -e -enable false AEselectButton;
  515.         button -e -enable false AEcopyButton;
  516.         $gAECurrentTab = "";
  517.         $gAEPrevCurrentTab = "";
  518.         clear $gAERelatedNodes;
  519.  
  520.     } else {
  521.  
  522.         formLayout -e -visible false $gAENothingSelectedLayout;
  523.         formLayout -e -visible true $gAEBaseLayoutName;
  524.  
  525.         AEbuildAllTabs $node;
  526.         AEbuildControls;
  527.  
  528.         string $firstTab = `nameField -q -o tabNameField0`;
  529.         $gAEFocusNode = $firstTab;
  530.         if ( $firstTab != "" ) {
  531.             string $tokens[];
  532.             tokenize($firstTab,"|",$tokens);
  533.             $firstTab = $tokens[size($tokens)-1];
  534.             if( `window -exists $gAttributeEditorWindowName` ) {
  535.                 window -e
  536.                     -title ("Attribute Editor: "+$firstTab)
  537.                     $gAttributeEditorWindowName;
  538.             }
  539.         }
  540.  
  541.         updateAEStack($node);
  542.  
  543.         button -e -enable true AEselectButton;
  544.         button -e -enable true AEcopyButton;
  545.     }
  546. }
  547.  
  548.